package com.lmh.backend.service.serviceImpl;

import com.lmh.backend.dao.AuthorDao;
import com.lmh.backend.dao.NewsDao;
import com.lmh.backend.entity.Author;
import com.lmh.backend.entity.News;
import com.lmh.backend.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    private NewsDao newsDao;
    private AuthorDao authorDao;
    @Autowired
    public void setNewsDao(NewsDao newsDao) {
        this.newsDao = newsDao;
    }
    @Autowired
    public void setAuthorDao(AuthorDao authorDao) {
        this.authorDao = authorDao;
    }
    @Override
    public List<News> getAllNews() {
        return newsDao.getAllNews();
    }

    @Override
    public List<News> getWaitCheckNews() {
        return newsDao.getWaitCheckNews();
    }

    @Override
    public News getNewsById(Long newsId) {
        return newsDao.getNewsById(newsId);
    }

    @Override
    public void passNews(Long newsId) {
        newsDao.passNews(newsId);
    }

    @Override
    public void delNews(Long newsId) {
        newsDao.delNews(newsId);
    }

    @Override
    public void addNews(String title, String content, String authorName) {
        Author author = authorDao.getAuthorByName(authorName);
        News news = new News();
        news.setAuthor(author);
        news.setTitle(title);
        news.setContent(content);
        newsDao.save(news);
    }

    @Override
    public void editNews(Long newsId, String new_title, String new_content) {
        newsDao.editNews(newsId, new_title, new_content);
    }
}
